package com.coderdream.chapter15.facade.a2;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class Database {

	private Database() {
	}

	/**
	 * 从数据库名称取得Properties
	 * 
	 * @param dbname
	 * @return
	 */
	public static Properties getProperties(String dbname) {
		 String filename = "src\\com\\coderdream\\chapter15" +
		 "\\facade\\sample\\pagemaker\\"
		 + dbname + ".txt";
		Properties prop = new Properties();
		//String filename = null;

		try {
			File directory = new File("."); 
			String p = directory.getCanonicalPath();
			

			//filename = p + "//" +  dbname + ".txt";		
			//System.out.println("Path: " + p);
			//System.out.println("Name: " + filename);
			prop.load(new FileInputStream(filename));
		} catch (IOException e) {
			System.out.println("Warning: " + filename + " is not found.");
		}

		return prop;
	}
}
